package com.demoweb.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.demoweb.model.dao.BoardDao;
import com.demoweb.model.dao.MemberDao;
import com.demoweb.model.dto.Board;
import com.demoweb.model.dto.Membership;

@WebServlet("/board/reply.action")
public class BoardReplyServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		//2. Board 객체를 생성하고 입력된 데이터를 읽어서 객체에 저장
		Board board = new Board();
		board.setBoardNo(
			Integer.parseInt(req.getParameter("boardno")));
		board.setTitle(req.getParameter("title"));
		board.setWriter(req.getParameter("writer"));
		board.setContent(req.getParameter("content"));

		//3. 데이터베이스에 변경 사항 적용
		BoardDao dao = new BoardDao();
		dao.insertReply(board);

		//4. view.action 이동
		String pageNo = "1";
		if (req.getParameter("pageno") != null)
			pageNo = req.getParameter("pageno");

		resp.sendRedirect(String.format(
			"view.action?boardno=%d&pageno=%s",
			board.getBoardNo(), pageNo));
		
		
		
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		
		doGet(req, resp);
	}
	
}






